<template>
    <div>
        <el-form label-width="100px" :model="sendFormData" :rules="rules" :size="customStyle.size" ref="validateDesignForm">
            <el-form-item label="主题背景：">
                <upload :isDesign="true" @change="changeImg"></upload>
            </el-form-item>

            <el-form-item label="聊天通知：">
                <el-radio-group v-model="chatStatus">
                    <el-radio-button :label="1">开启</el-radio-button>
                    <el-radio-button :label="0">关闭</el-radio-button>
                </el-radio-group>
            </el-form-item>
            <el-form-item>
                <el-button type="info" :loading="apiLoading" @click="$router.go(-1)">返回</el-button>
                <el-button type="primary" :loading="apiLoading" @click="handleSubmit">保存</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import Upload from '@/components/upload'
import {setDesign} from '@/api/user'
import {mapGetters} from "vuex";
export default {
    name: "password",
    components: {
        Upload
    },
    computed: {
        ...mapGetters([
            'previewThemeImg',
        ]),
        chatStatus:{
            get(){
                return this.$store.state.user.chatStatus
            },
            set(v){
                this.$store.commit('user/SET_CHAT_STATUS',v)
            }
        }
    },
    data(){
        return {
            sendFormData:{
                themeImg:"",
                username:'',
            },
            rules: {
                username: [
                    { required:true, trigger: 'blur',message:"用户名不能为空" }
                ],
                themeImg: [
                    {required:true, trigger: 'blur',message:"背景图片不能为空" }
                ]
            }
        }
    },
    created() {
        this.sendFormData.username=this.userInfo.username
    },
    methods:{
        changeImg(){
            this.sendFormData.themeImg=this.previewThemeImg
        },
        handleSubmit(){
            this.$refs.validateDesignForm.validate((valid) => {
                if(valid){
                    setDesign(this.sendFormData).then(res=>{
                        this.$store.commit('user/SET_THEME_BG',this.previewThemeImg)
                        this.$message.success(res.msg)
                    })
                }
            })
        }
    }
}
</script>

<style scoped>

</style>
